﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.Permission.Interfaces;
using Micrhard.FMCG.Server.Models;
using Micrhard.FMCG.Server.DataAccess;

namespace Micrhard.FMCG.Server.Impl
{
    public class OrderWorkSheetPermissionVal : ICustomeDataPermissionValidator
    {
        public bool HasPermission(List<Guid> identity)
        {
            bool result = false;
            MicrhardFMCGServerEntities db = new MicrhardFMCGServerEntities();
            var user = this.scope.EmpInfo;
            if (user.CompanyRange == (int)Range.Documenter || user.CompanyRange == (int)Range.Manager)
            {
                //是否是公司内的订单
                var cnt = db.Orders.Count(s => identity.Contains(s.OrderID) && s.CompanyID == user.CompanyID);
                if (cnt > 0)
                {
                    result = true;
                }
                else
                {
                    //对orderworksheet进行判断
                    foreach (var i in identity)
                    {
                        if (this.scope.PKID.Contains(i))
                        {
                            result = true;
                            break;
                        }
                    }
                }
            }
            return result;
        }

        public Microhard.Core.DBUtility.ScopeResult scope
        {
            set;
            get;
        }
    }
}
